package insight.google.game.era.servlet;

import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class GameServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws IOException {
    	UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        if (user != null) {
            resp.setContentType("text/html");
            
            resp.getWriter().println("Hello, " + user.getNickname());
            resp.getWriter().println("USER Information is as below."
            		+ "<br>Email: " + user.getEmail()
            		+ "<br>Nickname: " + user.getNickname()
            		+ "<br>Auth Domain: " + user.getAuthDomain()
            		+ "<br>UserID" + user.getUserId());
            String logoutURL = userService.createLogoutURL("http://www.spectrum.co.jp");
            
            resp.sendRedirect(logoutURL);
        } else {
        	resp.sendRedirect(req.getRequestURI());
        	
        	/*
        	StringBuffer url = req.getRequestURL();
        	int offset = url.indexOf("//") + 2;
        	resp.sendRedirect("http://" + url.substring(offset, url.indexOf('/', offset)));
        	*/
        }
    }
}